package network;

import android.content.Context;

import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.GenericsCallback;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.Request;

/**
 * Created by Ren on 2017/12/5.
 */

public class NetWork {

    static private String BAES_URL = "https://www.st12306.cn/app-ljyyx/rest/app/";
    static private Map<String, String> mHead = new HashMap<>();

    static {
        //在这里添加公共head属性
    }


    static void post(String url, String content, GenericsCallback callback, Context context) {
        OkHttpUtils
                .postString()
                .url(mergeUrl(url))
                .tag(context)
                .headers(mHead)
                .content(content)
                .build()
                .execute(callback);
    }

    static void post(String url, Map heads, GenericsCallback callback, Context context) {
        OkHttpUtils.post()
                .url(mergeUrl(url))
                .tag(context)
                .headers(mergeHead(heads))
                .build()
                .execute(callback);
    }


    static private String mergeUrl(String s) {

        return BAES_URL + s;
    }

    //添加公共头属性
    static private Map mergeHead(Map head) {
        mHead.putAll(head);
        return mHead;
    }
}
